package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.GoodDTO;
import com.sky.dto.GoodPageQueryDTO;
import com.sky.entity.Good;
import com.sky.enumeration.OperationType;
import com.sky.vo.GoodVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface GoodMapper {

    @Insert( "insert into good (name, price, description, image, category_id, status, create_time, update_time, create_user, update_user) " +
            "values (#{name}, #{price}, #{description}, #{image}, #{categoryId}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @AutoFill(value = OperationType.INSERT)
    void insert(Good goods);

    Page<GoodVO> pageQuery(GoodPageQueryDTO goodPageQueryDTO);

    @Delete("DELETE FROM good WHERE id = #{id}")
    void deleteById(Long id);

    @Select("SELECT * FROM good WHERE id = #{id}")
    Good getById(Long id);

    @Select("SELECT * FROM good WHERE category_id = #{categoryBack}")
    List<Good> getbyCategory(String categoryBack);
}
